package lixp.rabbitmqAdvance.producer.config;

import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ProConfig {

    //Rabbitmq的连接工厂
    @Autowired
    private CachingConnectionFactory connectionFactory;

    @Bean
    public MessageConverter messageConverter(){
        return new Jackson2JsonMessageConverter();
    }

    //这里需要手动创建队列，因此需要用到RabbitAdmin,所以在配置文件中进行创建
    @Bean
    public RabbitAdmin getRabbitAdmin() {
        return new RabbitAdmin(connectionFactory);
    }
}
